#include <bits/stdc++.h>
using namespace std;
using ll = long long;
map<string,int>mp;
string check(int n)
{
	string s;
	while(n)
	{
		if(n&1)s+='1';
		else s+='0';
		n>>=1;
	}
	reverse(s.begin(),s.end());
	return s;
}
int main()
{
	int n;
	cin>>n;
	for(int i=1;i<=n;i++)
	{
		int a,b;
		cin>>a>>b;
//		cout<<check(a)<<" "<<a<<endl;
		mp[check(a)]=b;
	}
	for(auto i:mp)
	{
		if(i.second>1)
		{
			string ss=i.first+'0';
			mp[ss]+=i.second/2;
			mp[i.first]%=2;
		}
//		cout<<i.first<<" "<<i.second<<endl;
	}
	ll ans=0;
	for(auto i:mp)
	{
		ans+=i.second;
	}
	cout<<ans;
	return 0;
}
